import axios from "../../http/axios.js";
import {
  apiGetEmployeeEmergencyContact
} from "../../http/server.js";

Page({
  data: {
    noList: {
      img: "/assets/img/nojjlxr.png",
      text: "您还没有添加紧急联系人~"
    },
    list: [
      // {
      //   name: "张三",
      //   sex: "男",
      //   relationship: "朋友"
      // },
      // {
      //   name: "李四",
      //   sex: "女",
      //   relationship: "父母"
      // }
    ]
  },

  onLoad: function(options) {},

  onReady: function() {},

  onShow: function() {
    this.getList();
  },
  // 获取职工紧急联系人
  getList: function() {
    let userInfo = wx.getStorageSync("userInfo")
    axios({
      url: apiGetEmployeeEmergencyContact,
      data: {
        workersId: userInfo.workersId
      }
    }).then(res => {
      let list = [];
      res.emergencyContacts.forEach((item, index) => {
        let obj = {
          ...item,
          name: item.name,
          relationship: item.relation,
          sex: item.sex == 1 ? "男" : "女"
        }
        list.push(obj)
      })
      this.setData({
        list
      })
    })
  },
  //编辑紧急联系人
  editContacts: function(e) {
    wx.navigateTo({
      url: `/pages/n_updateUrgentContacts/n_updateUrgentContacts?type=edit&item=${JSON.stringify(e.detail)}`,
    })
  },
  //添加紧急联系人
  addContacts: function() {
    wx.navigateTo({
      url: "/pages/n_updateUrgentContacts/n_updateUrgentContacts?type=add",
    })
  }
})